package com.dao;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.bean.*;
import com.inter.userInter;

public class staffDao{//ʵ���������������ν��ֻ�����÷�����ͳһ���ѡ�
	private SqlSession session;
	private userInter inter;
	
	public void initSession() {
		if(session!=null && inter!=null) return;
		String resource = "conf.xml";
        InputStream is = staffDao.class.getClassLoader().getResourceAsStream(resource);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
        session = sessionFactory.openSession();
        inter = session.getMapper(userInter.class);
	}
	
	public List<Map> selectAllMsg(){//��ѯ���е���Ϣ��Ŀ
		initSession();
		return inter.selectAllMsg();
	}
	
	public List<staff> selectStaffByName(String name) {
		initSession();
		return inter.selectStaffByName(name);
	}
	public List<passPort> selectPassPortBySid(int sid) {
		initSession();
		return inter.selectPassPortBySid(sid);
	}
	public List<action> selectActionByPid(String pid) {
		initSession();
		return inter.selectActionByPid(pid);
	}
	
	public void addStaff(staff s) {
		initSession();
		inter.addStaff(s);
		session.commit();
	}
	public void addPassPort(passPort p) {
		initSession();
		inter.addPassPort(p);
		session.commit();
	}
	public void addAction(action a) {
		initSession();
		inter.addAction(a);
		session.commit();
	}
	
	public void delAction(String id,String outdate) {
		initSession();
		Map m = new HashMap();
		m.put("pid", id);
		m.put("outdate", outdate);
		inter.delAction(m);
		session.commit();
	}
	
	public List<Map> search(Map m){
		initSession();
		return inter.search(m);
	}
	
	public List<Map> isreturnpp(Map m){
		initSession();
		return inter.isreturnpp(m);
	}
	
	public List<Map> searchOutDate(){
		initSession();
		return inter.searchOutDate();
	}
	
	public void modifyStaff(staff s) {
		initSession();
		inter.modifyStaff(s);
		session.commit();
	}
	public void modifyPassport(passPort p) {
		initSession();
		inter.modifyPassport(p);
		session.commit();
	}
	
	public List<Map> getweihuiguo(){
		initSession();
		return inter.getweihuiguo();
	}
	public List<Map> getweidaoqi(){
		initSession();
		return inter.getweidaoqi();
	}
	
	public void updateAction(passPort p) {
		initSession();
		inter.updateAction(p);
		session.commit();
	}
	
	public List<Map> export(){
		initSession();
		return inter.export();
	}
	

}
